package com.itrip.itripbiz.controller;


import com.itrip.itripbiz.service.HotelService;
import com.itrip.itripbiz.util.Dto;
import com.itrip.itripbiz.util.DtoUtil;
import com.itrip.itripbiz.util.EmptyUtils;
import com.itrip.itripbiz.util.Page;
import com.itrip.itripbiz.vo.SearchHotCityVO;
import com.itrip.itripbiz.vo.SearchHotelVO;
import com.itrip.itripbiz.vo.itripHotelVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 酒店表 前端控制器
 * </p>
 *
 * @author 四阶段项目二组
 * @since 2020-02-25
 */
@RestController
@RequestMapping("/search/api/hotellist")
@CrossOrigin
public class HotelController {
    @Autowired
    private HotelService hotelService;
    @ApiOperation("查询酒店信息")
    @PostMapping("/searchItripHotelPage")
    public Dto searchItripHotelPage(
            @ApiParam(name = "searchHotelVO", value = "查询对象", required = false)
            @RequestBody SearchHotelVO searchHotelVO){
        Page page = null;
        if (EmptyUtils.isEmpty(searchHotelVO) || EmptyUtils.isEmpty(searchHotelVO.getDestination())) {
            return DtoUtil.returnFail("目的地不能为空", "20002");
        }
        try {
            page = hotelService.searchItripHotelPage(searchHotelVO,searchHotelVO.getPageNo(), searchHotelVO.getPageSize());
        }catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "20001");
        }
        return DtoUtil.returnDataSuccess(page);
    }
    @ApiOperation("查询热门城市信息")
    @PostMapping("/searchItripHotelListByHotCity")
    public Dto<Page<itripHotelVo>> searchItripHotelListByHotCity(
            @ApiParam(name = "searchHotelVO", value = "查询对象", required = false)
            @RequestBody SearchHotCityVO searchHotelVO) throws Exception {
        if (EmptyUtils.isEmpty(searchHotelVO) || EmptyUtils.isEmpty(searchHotelVO.getCityId())) {
            return DtoUtil.returnFail("城市id不能为空");
        }
       /* Map<String, Object> param = new HashMap<>();
        param.put("cityId", vo.getCityId());*/
        List<itripHotelVo> list = hotelService.searchItripHotelListByHotCity(searchHotelVO.getCityId(), searchHotelVO.getCount());
        return DtoUtil.returnDataSuccess(list);
    }

}
